package com.bwda.dsrs.base.jar.util.HotDeploy;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;


/**
 * @author yanzz
 * 说明 ：
 *       通过反射调用 net.bwda.remote.utils.FtpUtil 类下的testString 方法
 *
 */
public class HotDeployHelper {

    //sdk路径需要修改成你本地的路径
    private static String jarPath = "F:/bwda-remote-0.0.1-SNAPSHOT.jar";

    //动态加载的包路径
    //这边输入 net/bwda/remote/utils/ 意思是将 net/bwda/remote/utils/ 下的所有class 文件进行重新加载
    private static String [] packageNameArray = {"net/bwda/remote/utils/","net/bwda/remote/exception/"};




    /**
     * 测试demo方法
     * @param method   方法名
     * @param param    方法中的参数
     *                 本示例测试的是testString 方法 无需传入参数
     */
    public static void testMethod(String method, Object ... param){
        MyHotSdkDeployClassLoader myHotSdkDeployClassLoader =  MyHotSdkDeployClassLoader.builder()
                .jarPath(jarPath)
                .packageNameArray(packageNameArray).build();

        Class cls = null;
        try {
            //动态加载某个类
            cls = myHotSdkDeployClassLoader.loadClass("net.bwda.remote.utils.FtpUtil");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
            //反射的方式调用方法
            Object object= null;
        try {
            object = cls.newInstance();
            Method m = cls.getMethod(method);
            String message = (String)m.invoke(object, param);
            System.out.println(message);
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }


    }

}
